package dd.tools;

public class CounterInArray {

	/**
	 * @param args
	 */
	static int[] index = new int[3];
	static int k = 5;
	static boolean done = false;

	public static void next() {
		while (!done) {
			boolean reset = false;
			int sum = 0;
			// stop?
			if (index[index.length - 1] == k) {
				done = true;
			}
			//sum?
			for (int i = 0; i < index.length; i++)
				sum += index[i];
			//check sum
			if (sum <= k) {
				// if (true) {
				for (int i = 0; i < index.length; i++) {
					System.out.print(index[i] + " ");
				}
				System.out.println();
			}
			//update values
			for (int i = 0; i < index.length - 1; i++) {
				if (index[i] >= k) {
					index[i] = 0;
					index[i + 1]++;
					reset = true;
				}
			}
			if (!reset)
				index[0]++;
		}
	}

	public static void main(String[] args) {
		next();

	}

}
